<?php
class LanguageSelector extends CWidget
{
    public function run()
    {
        Yii::import('application.models.local.Language');

        $this->render('languageSelector', array(
            'currentLang'=>Yii::app()->language,
            'languages'=>Language::model()->all,
        ));
    }

    public function createMultilanguageReturnUrl($lang='')
    {
        if(!$lang) $lang=Yii::app()->language;
        if(count($_GET)>0){
            $attr=$_GET;
            $attr['language']=$lang;
        }else
            $attr=array('language'=>$lang);

        return Yii::app()->createUrl('', $attr);
    }
}